const ioredis=require('./ioredis');
const redLock=require('redlock');
const { settings } = require('../../app');

const redlock=new redLock(ioredis,
   {
    //本地使用飘逸时间
    driftFactor: 0.01,
    retryCount:10,
    retryDelay:200,
    retryJitter:200,
    automaticExtensionThreshold: 500
});
//示例
var locksource=Math.floor(Date.now())+'test';
let lock=await redlock.lock(locksource,1000).then(function(lock){
    //业务代码
    return lock.unlock().catch(function(err){
        console.error(err);
    })
});

//示例2
// Acquire a lock.
let lock2 = await redlock.acquire(["a"], 5000);
try {
  // Do something...
  await something();

  // Extend the lock.
  lock2 = await lock2.extend(5000);

  // Do something else...
  await somethingElse();
} finally {
  // Release the lock.
  await lock2.release();
}

